#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <time.h>
#include <ctype.h>

int roll_dice(void);
bool play_game(void);

int main() {
    int win_count = 0, lose_count = 0;
    char ch;

    srand((unsigned) time(NULL));
    
    do {
        if (play_game()) {
            win_count++;
            printf("You win!");
        } else {
            lose_count++;
            printf("You lose!");
        }

        printf("\nPlay again? ");
        scanf(" %c", &ch);
    } while (toupper(ch) == 'Y');

    printf("\nWins: %d, Loses: %d\n", win_count, lose_count);

}

int roll_dice(void) {
    return rand() % 6 + rand() % 6 + 2;
}

bool play_game(void) {
    int point, target;

    point = roll_dice();
    printf("You rolled: %d\n", point);

    if (point == 7 || point == 11) {
        return true;
    } else if (point == 2 || point == 3 || point == 12) {
        return false;
    } else {
        target = point;
    }

    while (true) {
        point = roll_dice();
        printf("Your rolled: %d\n", point);

        if (point == target) return true;
        else if (point == 7) return false;
    }
}
